/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.noticias;

import DBMS.DataBaseManager;
import clases.Noticia;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class AgregarNoticia extends DispatchAction {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";

    public ActionForward save(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Noticia noticia = (Noticia) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        if (dbms.agregarNoticia(noticia)) {
            noticia.setMensaje("Noticia publicada satisfactoriamente.");
            noticia.cleanAttributes();
            return mapping.findForward(SUCCESS);
        } else {
            noticia.setMensaje("No se pudo publicar la noticia.");
            return mapping.findForward(FAILURE);
        }
    }

    public ActionForward page(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        return mapping.findForward("page");
    }
}
